package com.agileboot.attendance.domain.settlement.db.service.impl;

import com.agileboot.attendance.domain.settlement.db.service.AttSettlementService;
import com.agileboot.attendance.domain.settlement.entity.AttSettlementEntity;
import com.agileboot.attendance.domain.settlement.mapper.AttSettlementMapper;
import com.agileboot.attendance.domain.settlement.dto.SettlementQuery;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 结算单数据库服务实现类
 */
@Service
public class AttSettlementServiceImpl extends ServiceImpl<AttSettlementMapper, AttSettlementEntity>
    implements AttSettlementService {

    @Override
    public Page<AttSettlementEntity> queryPage(SettlementQuery query) {
        Page<AttSettlementEntity> page = new Page<>(query.getPageNum(), query.getPageSize());
        LambdaQueryWrapper<AttSettlementEntity> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Objects.nonNull(query.getProjectId()), AttSettlementEntity::getProjectId, query.getProjectId())
                .eq(Objects.nonNull(query.getOrderId()), AttSettlementEntity::getOrderId, query.getOrderId())
                .eq(Objects.nonNull(query.getSupplierId()), AttSettlementEntity::getSupplierId, query.getSupplierId())
                .eq(Objects.nonNull(query.getStatus()), AttSettlementEntity::getStatus, query.getStatus())
                .like(Objects.nonNull(query.getBillNo()), AttSettlementEntity::getBillNo, query.getBillNo())
                .ge(Objects.nonNull(query.getStartTime()), AttSettlementEntity::getStartDate, query.getStartTime())
                .le(Objects.nonNull(query.getEndTime()), AttSettlementEntity::getEndDate, query.getEndTime())
                .orderByDesc(AttSettlementEntity::getCreateTime);
        return page(page, wrapper);
    }
}
